package com.hdq.controller.admin;

import com.hdq.result.PageResult;
import com.hdq.result.Result;
import com.hdq.service.RoleService;
import dto.RoleAddDTO;
import dto.RoleEditDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vo.RoleXiaLaListVO;

import java.util.List;

@RestController
@RequestMapping("/admin/role")
@Tag(name = "角色管理")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping
    @Operation(summary = "查询角色列表")
    public Result<List<RoleXiaLaListVO> > select() {
        List<RoleXiaLaListVO> list= roleService.selectXiaLa();
        return Result.success(list);
    }

    @GetMapping("/{page}")
    @Operation(summary = "分页查询角色列表")
    public Result<PageResult> selectByPage(@PathVariable Integer page,@RequestParam Integer pageSize) {
        PageResult list= roleService.selectByPage(page,pageSize);
        return Result.success(list);
    }

    @PostMapping
    @Operation(summary = "新增角色")
    public Result insert(@RequestBody RoleAddDTO roleAddDTO) {
        roleService.insert(roleAddDTO);
        return Result.success();
    }

    @DeleteMapping
    @Operation(summary = "删除角色/批量删除")
    public Result delete(@RequestParam List<Long> ids) {
        roleService.delete(ids);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "更新角色")
    public Result update(@RequestBody RoleEditDTO roleEditDTO) {
        roleService.update(roleEditDTO);
        return Result.success();
    }
}
